// config/shortcuts.ts
// 快捷键配置文件

export interface ShortcutConfig {
  key: string;
  description: string;
  enabled: boolean;
  action: string; // 路由路径或其他操作标识
}

export const defaultShortcuts: ShortcutConfig[] = [
  {
    key: 'Ctrl+D',
    description: '跳转到数据概览',
    enabled: true,
    action: '#/dashboard'
  },
  {
    key: 'Ctrl+R',
    description: '跳转到智能对账',
    enabled: true,
    action: '#/finance/reconciliation/workbench'
  },
  {
    key: 'Ctrl+O',
    description: '跳转到销售订单',
    enabled: true,
    action: '#/sales/orders'
  },
  {
    key: 'Ctrl+T',
    description: '跳转到银行流水',
    enabled: true,
    action: '#/finance/transactions'
  },
  {
    key: 'Ctrl+C',
    description: '跳转到客户管理',
    enabled: false, // 默认禁用以避免与复制冲突
    action: '#/sales/customers'
  },
  {
    key: 'F5',
    description: '刷新页面',
    enabled: true,
    action: 'reload'
  },
  {
    key: 'Ctrl+Shift+T',
    description: '切换主题',
    enabled: true,
    action: 'toggleTheme'
  },
  {
    key: 'Ctrl+B',
    description: '切换侧边栏',
    enabled: true,
    action: 'toggleSidebar'
  }
];

// 从localStorage加载用户自定义配置
export const loadUserShortcuts = (): ShortcutConfig[] => {
  try {
    const saved = localStorage.getItem('user-shortcuts');
    if (saved) {
      const parsed = JSON.parse(saved);
      // 合并默认配置和用户配置
      return defaultShortcuts.map(defaultShortcut => {
        const userShortcut = parsed.find((s: any) => s.key === defaultShortcut.key);
        return userShortcut ? { ...defaultShortcut, ...userShortcut } : defaultShortcut;
      });
    }
  } catch (error) {
    console.warn('加载用户快捷键配置失败:', error);
  }
  return defaultShortcuts;
};

// 保存用户自定义配置到localStorage
export const saveUserShortcuts = (shortcuts: ShortcutConfig[]): void => {
  try {
    localStorage.setItem('user-shortcuts', JSON.stringify(shortcuts));
  } catch (error) {
    console.warn('保存用户快捷键配置失败:', error);
  }
};